package database;
import java.sql.*;

public class Transaction {
    public static void main(String [] args)
    {
        //创建java和mysql数据库之间连接的桥梁
        try{
            Class.forName("com.mysql.jdbc.Driver");
            System.out.println("连接数据库成功" );
        }catch(Exception e)
        {
            System.out.println("注册驱动失败");
            e.printStackTrace();}
        String url="jdbc:mysql://localhost:3306/zhuce?useSSL=FALSE&serverTimezone=UTC";
        Connection conn=null;
        try{
            conn=DriverManager.getConnection(url,"root","123456789");
            System.out.println("登陆数据库成功");
            Statement statement=conn.createStatement();//创建数据库执行对象
            System.out.println("创建Statement成功");
            //返回的是方法名
            ResultSet rssultset=statement.executeQuery("select id,name,password,email,birthday from users");
           //executeUpdate()返回的是整型
            //int result=statement.executeUpdate("update users set name='tangygnag' where id=2022");
            while(rssultset.next())
            {
                System.out.println(rssultset.getString(1)+","+rssultset.getString(2)
                +rssultset.getString(4));
            }
            rssultset.close();
            statement.close();
            conn.close();
            //conn.setAutoCommit(false);//设置关闭自动提交



        }catch(SQLException e){e.printStackTrace();}
    }
}
